local cjson = require 'cjson.safe';
stringExt = require '..util.string_ext';
server = require "dns.server";

local machine_ip = '192.168.9.232'

local file = io.open('./conf/data.json', 'r');

if  not file then
    ngx.log(ngx.ERR, 'stream system failed to load data file.')
    return ngx.exit()
end

local content = file:read('*all')

local data = cjson.decode(content);

local hostArr = ngx.shared.hosts

local index = 0
for i,v in pairs(data) do
    if v.type ~= '0' then
        hostArr:set(i, v.type .. '|' .. v.value);
    else
        hostArr:set(i, server.TYPE_A .. '|' .. machine_ip);
    end
    index = index + 1
end

ngx.log(ngx.INFO, 'stream system loaded rules:', index);

file:close()